cmake_minimum_required (VERSION 3.16)

project (halley)

if (NOT HALLEY_PROJECT_EMBED)
    set(HALLEY_PATH ${CMAKE_CURRENT_SOURCE_DIR})
    set(BUILD_HALLEY_TOOLS 1 CACHE BOOL "Build editor and commandline tools")
    set(BUILD_HALLEY_TESTS 1 CACHE BOOL "Build tests")
    set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${HALLEY_PATH}/cmake/")
    include(HalleyProject)
endif ()

set(HALLEY_BIN "bin")
set(HALLEY_LIB "lib")
if(CMAKE_SIZEOF_VOID_P EQUAL 4) # 32-bit build
    set(HALLEY_BIN "bin32")
    set(HALLEY_LIB "lib32")
endif()

include_directories(src/contrib)

if (NOT USE_GDK)
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${HALLEY_BIN})
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/${HALLEY_BIN})
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/${HALLEY_BIN})
    set(CMAKE_RUNTIME_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_CURRENT_SOURCE_DIR}/${HALLEY_BIN})

    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${HALLEY_BIN})
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/${HALLEY_BIN})
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/${HALLEY_BIN})
    set(CMAKE_LIBRARY_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_CURRENT_SOURCE_DIR}/${HALLEY_BIN})

    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/${HALLEY_LIB})
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELEASE ${CMAKE_CURRENT_SOURCE_DIR}/${HALLEY_LIB})
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_DEBUG ${CMAKE_CURRENT_SOURCE_DIR}/${HALLEY_LIB})
    set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_RELWITHDEBINFO ${CMAKE_CURRENT_SOURCE_DIR}/${HALLEY_LIB})
endif()

set(CMAKE_EXPORT_COMPILE_COMMANDS ON)

SET(HALLEY_VERSION_MAJOR "2")
SET(HALLEY_VERSION_MINOR "0")
SET(HALLEY_VERSION_PATCH "0")
SET(HALLEY_VERSION "${HALLEY_VERSION_MAJOR}.${HALLEY_VERSION_MINOR}.${HALLEY_VERSION_PATCH}")

if (IS_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../halley-external")
    set(BIN_DIR_LEN 0)
    string(LENGTH "${CMAKE_BINARY_DIR}" BIN_DIR_LEN)
    #math(EXPR BIN_DIR_LEN "${BIN_DIR_LEN} - 1")
    string(SUBSTRING "${CMAKE_BINARY_DIR}" 0 "${BIN_DIR_LEN}" EXTERNAL_BIN_DIR)
    add_subdirectory("${CMAKE_CURRENT_SOURCE_DIR}/../halley-external" "${EXTERNAL_BIN_DIR}-external")
endif()

add_subdirectory(deps)
add_subdirectory(src)

if (DEV_BUILD AND HALLEY_HAS_LIVEPP)
    target_compile_definitions(halley-engine PUBLIC -DHAS_LIVEPP PRIVATE -DLIVEPP_PATH="${CMAKE_SOURCE_DIR}/LivePP")
    target_include_directories(halley-engine PRIVATE ${CMAKE_SOURCE_DIR}/LivePP/API/x64)
endif()
